/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

$(function() {
    Loading.finish();
});

function c2tab1onload() {
    ajaxLoadOrderlist();
}

function c2tab2onload() {
    ajaxLoadOrderlistAll();
}

/**
 * 加载订单列表
 * @returns {undefined}
 */
function ajaxLoadOrderlist() {
    wpLoading();
    $.get('?/Wdmin/ajaxLoadOrderlist/page=0', function(r) {
        $('#orderlist').html(r);
        $(".various").fancybox({
            openEffect: 'fade',
            closeEffect: 'elastic',
            openSpeed: 'fast',
            closeSpeed: 'fast',
            overlayColor: '#fff',
            scrolling : false,
            afterLoad: function(r) {
                window.corder1 = parseInt($(r.element[0]).attr('data-orderid'));
            }
        });
        Loading.finish();
    });
}

/**
 * 加载订单列表 全部订单
 * @returns {undefined}
 */
function ajaxLoadOrderlistAll() {
    wpLoading();
    $.get('?/Wdmin/ajaxLoadOrderlist/page=0&status=all', function(r) {
        Loading.finish();
        $('#card2-subtab2').html(r);
    });
}

/**
 * despatch goods
 * @params window.corder1 选中orderid
 * @returns {undefined}
 */
function despatch() {
    var orderId = window.corder1;
    var despatchExpressCode = $('#despatchExpressCode').val();
    var expressCompany = $('#expressCompany').val();
    if (despatchExpressCode === "") {
        $('#despatchExpressCode').addClass('shake').css('border-color', '#900');
        setTimeout(function() {
            $('#despatchExpressCode').removeClass('shake');
        }, 500);
    } else {
        // 发货走起
        $.post('?/Order/ExpressReady', {
            'orderId': orderId,
            'ExpressCode': despatchExpressCode,
            'expressCompany': expressCompany
        }, function(res) {
            debug(res);
            if (res === "1") {
                Alert('发货成功');
                $.fancybox.close();
                $('#orderlst' + orderId).slideUp();
                loadStatData();
            } else {
                Alert('failed');
            }
        });
    }
}
